<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="monthwsList" @selection-change="handleSelectionChange">
      <el-table-column label="用户" align="center" prop="userNick" fixed />
      <el-table-column label="日期" align="center" prop="ofcmpayMonth">
        <template slot-scope="scope">
          <span>{{ scope.row.wsmpayYear + "-" + scope.row.wsmpayMonth }}</span>
        </template>
      </el-table-column>
      <el-table-column label="底薪" align="center" prop="basicSalary" />
      <el-table-column label="扣款金额" align="center" prop="dmAmount" />
      <el-table-column label="考勤补贴" align="center" prop="workAllowance" />
      <el-table-column label="其他补助" align="center" prop="otherSubsidy" />
      <el-table-column label="绩效比例" align="center" prop="personalPerformance" />
      <el-table-column label="计件工资" align="center" prop="basicSalary" />
      <el-table-column label="工龄工资" align="center" prop="ageAllpay" />
      <el-table-column label="餐补" align="center" prop="mealAllowance" />
      <el-table-column label="高温补贴" align="center" prop="highTemperature" />
      <el-table-column label="早班次数" align="center" prop="earlyNum" />
      <el-table-column label="早班补助" align="center" prop="earlyShift" />
      <el-table-column label="晚班次数" align="center" prop="nightNum" />
      <el-table-column label="晚班补助" align="center" prop="nightShift" />
      <el-table-column label="加班补贴" align="center" prop="overtimeAllallowance" />
      <el-table-column label="应发工资" align="center" prop="wagePayable" />
      <el-table-column label="公积金" align="center" prop="providentFund" />
      <el-table-column label="社保" align="center" prop="socialSecurity" />
      <el-table-column label="代扣税" align="center" prop="taxDeduction" />
      <el-table-column label="每月实发" align="center" prop="netSalary" />
      <el-table-column label="满勤天数" align="center" prop="fullDay" />
      <el-table-column label="出勤天数" align="center" prop="attendanceDay" />
      <el-table-column label="缺勤天数" align="center" prop="absenceDay" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
  import {
    listMonthws,
    getMonthws,
    delMonthws,
    addMonthws,
    updateMonthws,
    getSingleMonthws
  } from "@/api/sl/monthws";

  export default {
    name: "Monthws",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 车间工资表格数据
        monthwsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userName: null,
          userNick: null,
          moduleId: null,
          workshopId: null,
          gprocessId: null,
          deptId: null,
          wsmpayYear: null,
          wsmpayMonth: null,
          levelId: null,
          ssmId: null,
          isHistory: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询车间工资列表 */
      getList() {
        this.loading = true;
        getSingleMonthws(this.queryParams).then(response => {
          this.monthwsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          wsmpayId: null,
          userName: null,
          userNick: null,
          moduleId: null,
          workshopId: null,
          gprocessId: null,
          deptId: null,
          wsmpayYear: null,
          wsmpayMonth: null,
          wsmpayStart: null,
          wsmpayEnd: null,
          basicSalary: null,
          levelPay: null,
          postPay: null,
          gradePay: null,
          educationPay: null,
          workAllowance: null,
          personalPerformance: null,
          deptPerformance: null,
          fixedSalary: null,
          totalReward: null,
          workingAge: null,
          ageBase: null,
          ageAllpay: null,
          agePay: null,
          mealAllowance: null,
          mealBase: null,
          highTemperature: null,
          earlyNum: null,
          earlyBase: null,
          earlyShift: null,
          nightNum: null,
          nightBase: null,
          nightShift: null,
          overtimeAllallowance: null,
          overtimeAllowance: null,
          wagePayable: null,
          providentFund: null,
          socialSecurity: null,
          taxDeduction: null,
          netSalary: null,
          fullDay: null,
          attendanceDay: null,
          absenceDay: null,
          attendancePay: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          levelId: null,
          ssmId: null,
          isHistory: null,
          dmAmount: null,
          otherSubsidy: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.wsmpayId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加车间工资";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const wsmpayId = row.wsmpayId || this.ids
        getMonthws(wsmpayId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改车间工资";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.wsmpayId != null) {
              updateMonthws(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addMonthws(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const wsmpayIds = row.wsmpayId || this.ids;
        this.$modal.confirm('是否确认删除车间工资编号为"' + wsmpayIds + '"的数据项？').then(function() {
          return delMonthws(wsmpayIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('sl/monthws/export', {
          ...this.queryParams
        }, `monthws_${new Date().getTime()}.xlsx`)
      },
      handleEarly() {
        this.form.earlyShift = (this.form.earlyBase * this.form.earlyNum).toFixed(2);
      },
      handleNight() {
        this.form.nightShift = (this.form.nightBase * this.form.nightNum).toFixed(2);
      }
    }
  };
</script>
<style>
  .el-table .el-table__body-wrapper::-webkit-scrollbar {
    height: 10px;
  }
</style>
